package com.yanqu.road.server.manger.unioncampwar.service;

import com.google.protobuf.InvalidProtocolBufferException;
import com.yanqu.road.pb.syncMessage.SyncMessage;
import com.yanqu.road.pb.unionCampWar.UnionCampWar;
import com.yanqu.road.server.game.service.IGameServiceCommand;
import com.yanqu.road.server.manger.unioncampwar.UnionCampWarPatronsMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.sync.message.SyncResponse;

public class UnionCampWarAttackPatronsCrossReqCmd implements IGameServiceCommand {
    @Override
    public SyncResponse execute(SyncMessage.Request request) throws InvalidProtocolBufferException {
        SyncResponse syncResponse = new SyncResponse();
        UnionCampWar.CrossUnionCampWarToGameAttackReqMsg reqMsg = UnionCampWar.CrossUnionCampWarToGameAttackReqMsg.parseFrom(request.getDataBytes());
        UnionCampWar.CrossUnionCampWarToGameAttackRespMsg.Builder respMsg = UnionCampWarPatronsMgr.battle(reqMsg);
        if (respMsg == null) {
            syncResponse.setErrorCode(GameErrorCode.E_ERROR_TIME_OUT);
        } else {
            syncResponse.setResponseBuilder(respMsg);
        }

        return syncResponse;
    }
}
